package cn.xfdzx.android.apps.shop.fragment;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.activity.login.OneLoginMainActivity;
import cn.xfdzx.android.apps.shop.adapter.ShopInGoodsCatoryListAdapter;
import cn.xfdzx.android.apps.shop.adapter.ShopInGoodslibrarListAdapter;
import cn.xfdzx.android.apps.shop.apps.Constants;
import cn.xfdzx.android.apps.shop.base.BaseMvpFragment;
import cn.xfdzx.android.apps.shop.bean.GoodsLiblaryListBean;
import cn.xfdzx.android.apps.shop.bean.GoodsLiblaryListSelBean;
import cn.xfdzx.android.apps.shop.bean.GoodsUpStateBeen;
import cn.xfdzx.android.apps.shop.bean.OneCategoryBeen;
import cn.xfdzx.android.apps.shop.bean.ShopAddGoodTypeBeen;
import cn.xfdzx.android.apps.shop.bean.ShopInGoodListBeen;
import cn.xfdzx.android.apps.shop.bean.UpdateNumPriceBeen;
import cn.xfdzx.android.apps.shop.contract.ShopInGoodListContract;
import cn.xfdzx.android.apps.shop.evenbus.SearchGoodsCloseMessage;
import cn.xfdzx.android.apps.shop.evenbus.SearchGoodsContentMessage;
import cn.xfdzx.android.apps.shop.evenbus.UpdateMessage;
import cn.xfdzx.android.apps.shop.presenter.ShopInGoodListPresenter;
import cn.xfdzx.android.apps.shop.util.EmptyUtil;
import cn.xfdzx.android.apps.shop.util.KeybordUtil;
import cn.xfdzx.android.apps.shop.util.ProgressDialog;
import cn.xfdzx.android.apps.shop.util.Utils;
import cn.xfdzx.android.apps.shop.util.UtilsData;
import cn.xfdzx.android.apps.shop.widget.ChooseShopCatgoryDialog;

import static cn.xfdzx.android.apps.shop.apps.Constants.APP_TOKEN;


/**
 * @author zf
 * @date 2020/8/1 0026
 * description： 商品管理 商品库
 */
public class ShopInGoodLibraryFragment extends BaseMvpFragment<ShopInGoodListPresenter> implements ShopInGoodListContract.View, View.OnClickListener {

    RecyclerView rv_librarygoods;
    SmartRefreshLayout mRefreshLayout;

    TextView tvHint;
    LinearLayout llHint;
    private int page = 1;
    private int limit = Constants.LIMIT;
    private String orderType, styleType;
    private List<ShopInGoodListBeen.DataBean> mList = new ArrayList();
    private Dialog dialog;
    private TextView tvDialogQueren;
    private String storeId;//店铺id
    private List<GoodsLiblaryListBean.DataBean> libraryData = new ArrayList();
    private RecyclerView recycle_catory;//横向分类列表
    private List<GoodsLiblaryListSelBean> selBeans = new ArrayList<>();
    private ShopInGoodslibrarListAdapter shopInGoodslibrarListAdapter;//
    private List<OneCategoryBeen.DataBean> catoryDate = new ArrayList<>();//商品库分类集合数据
    private List<GoodsLiblaryListBean.DataBean> alldataBeans = new ArrayList<>();//所有数据集合
    private ShopInGoodsCatoryListAdapter catoryListAdapter;//分类适配器
    private CheckBox checkbox_all;//全选
    private TextView tv_add;//导入商品
    private boolean selAll = false;//是否主动全选了
    private boolean isAllCheck = true;//是否被动全选了
    private int trueCount;//选择的数量
    private String categoryId;//分类id
    private int isSearch;
    private String searchMessage;
    private int selPosition = -1;//选择的小分类角标
    private ImageView img_returntop;//返回顶部
    private int mLastVisiblePosition;
    private List<ShopAddGoodTypeBeen.DataBean> catoryList;//切换弹窗的店铺分类数据
    private ChooseShopCatgoryDialog chooseShopCatgoryDialog;
    private Map<String,String> selGoodsMap = new HashMap<>();//记录选择的商品商品集合
    private int clickCatoryPosition;
    private boolean isShowToast;
    private String catoryTitle;
    private int oldSelCatoryPosition;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_shopgoodslibrary;
    }
    @Override
    protected void initView(View view) {
        rv_librarygoods = view.findViewById(R.id.rv_librarygoods);
        mRefreshLayout = view.findViewById(R.id.refreshLayout);
        tvHint = view.findViewById(R.id.tv_hint);
        llHint = view.findViewById(R.id.ll_hint);
        checkbox_all = view.findViewById(R.id.checkbox_all);
        tv_add = view.findViewById(R.id.tv_add);
        recycle_catory = view.findViewById(R.id.recycle_catory);
        img_returntop = view.findViewById(R.id.img_returntop);

        EventBus.getDefault().register(this);
        tvHint.setText("没有发现商品哦");
        orderType = getArguments().getString("orderType");
        styleType = getArguments().getString("styleType");
        mPresenter = new ShopInGoodListPresenter();
        mPresenter.attachView(this);
        tv_add.setOnClickListener(this);
        img_returntop.setOnClickListener(this);
        storeId = UtilsData.getPreference(getActivity(), "login").getString("storeId");
        Map<String,Object> map = new HashMap<>();
        map.put("storeId",storeId);
        map.put("page",page);
        map.put("goodsType","0");
        mPresenter.getLibraryList(true,true,map);
        mPresenter.getCategoryList();//请求店铺内分类
        Map<String,Object> mapCatory = new HashMap<>();
        mapCatory.put("pid","-1");
        mapCatory.put("index_status","1");
        mPresenter.getOneCategory(mapCatory);
        mRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                page = 1;
                Map<String,Object> map = new HashMap<>();
                map.put("storeId",storeId);
                map.put("page",page);
                map.put("goodsType","0");
                if (isSearch==1){//搜索商品
                    map.put("keyword",searchMessage);
                }else {
                    map.put("keyword","");
                    if (EmptyUtil.isNotEmpty(categoryId)){
                        map.put("categoryId",categoryId);
                    }
                }

                mPresenter.getLibraryList(true,true,map);
            }
        });
        dialog = new Dialog(getActivity(), R.style.ExitDialog);
        View layout = View.inflate(getActivity(), R.layout.dialog_good_bianji, null);
        dialog.setContentView(layout);
        dialog.setCanceledOnTouchOutside(true);
        layout.findViewById(R.id.tvw_dialog_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });

        tvDialogQueren = layout.findViewById(R.id.tv_dialog_queren);
        if (styleType.equals("0")) {
            tvDialogQueren.setTextColor(getResources().getColor(R.color.color_FB9129));
        } else {
            tvDialogQueren.setTextColor(getResources().getColor(R.color.color_02C557));
        }

        initRecycle();

       // initSelCatoryDialog();
    }

    /**初始化选择分类 */
    private void initSelCatoryDialog() {
        if (EmptyUtil.isNotEmpty(catoryList)){
            if (chooseShopCatgoryDialog==null){
                chooseShopCatgoryDialog = new ChooseShopCatgoryDialog(getActivity(),catoryList);
            }
            chooseShopCatgoryDialog.show();
            chooseShopCatgoryDialog.setDate(catoryTitle);

            chooseShopCatgoryDialog.setChoseTypeListener(new ChooseShopCatgoryDialog.setChoseTypeListener() {
                @Override
                public void onChoseType(String catoryId) {
                    //TODO:
                    selBeans.clear();
                    for (int i = 0; i < alldataBeans.size(); i++) {
                        if (alldataBeans.get(i).isChecked()){
                            //selBeans.add(new GoodsLiblaryListSelBean(alldataBeans.get(i).getId()+"",alldataBeans.get(i).getTitle()));
                            selBeans.add(new GoodsLiblaryListSelBean(alldataBeans.get(i).getId()+"",""));
                        }
                    }

                    Map<String,Object> map = new HashMap<>();
                    map.put("data",new Gson().toJson(selBeans));
                    map.put("storeId",storeId);
                    map.put("storeCategory",catoryId);
                    mPresenter.addGoods(map,catoryId);
                }
            });
        }else {
            Utils.toastMessage(getActivity(),"当前网络不佳，请刷新页面重试");
        }


    }

    private void initRecycle() {
        recycle_catory.setLayoutManager(new LinearLayoutManager(getActivity(),LinearLayoutManager.HORIZONTAL,false));
        catoryListAdapter = new ShopInGoodsCatoryListAdapter(catoryDate);
        recycle_catory.setAdapter(catoryListAdapter);
        //分类条目点击
        catoryListAdapter.setItemCatoryClickListener(new ShopInGoodsCatoryListAdapter.OnItemItemCatoryClickListener() {
            @Override
            public void onItemItemCatoryClick(int position, List<OneCategoryBeen.DataBean> catoryDate) {

                clickCatoryPosition = position;

                isShowToast = false;
                if ( isSelGoods()){


                }else {
                    //切换分类，粮油素食和水产
                    changeCatoryType(position, catoryDate);
                }

            }
        });

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        rv_librarygoods.setLayoutManager(linearLayoutManager);
        shopInGoodslibrarListAdapter = new ShopInGoodslibrarListAdapter(libraryData);
        rv_librarygoods.setAdapter(shopInGoodslibrarListAdapter);

        shopInGoodslibrarListAdapter.setItemCheckListener(new ShopInGoodslibrarListAdapter.OnItemOnClickListener() {
            @Override
            public void onItemCheckClick(int position, List<GoodsLiblaryListBean.DataBean> dataBeans) {
                alldataBeans = dataBeans;
                trueCount = 0;
               // Log.e("onItemCheckClick",alldataBeans.size()+"----");
                for (int i = 0; i < alldataBeans.size(); i++) {
                    if (alldataBeans.get(i).isChecked()){
                        trueCount++;
                    }else {
                        //isAllCheck = false;
                       //break;
                    }
                }
                if (trueCount == alldataBeans.size()){
                    checkbox_all.setChecked(true);
                }else {
                    checkbox_all.setChecked(false);
                }

                if (trueCount>0){
                    tv_add.setBackgroundResource(R.drawable.dfb9129_bg_r19);
                }else {
                    tv_add.setBackgroundResource(R.drawable.d999999_bg_r19);
                }

            }
        });

        /**全选按钮点击*/
        checkbox_all.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (!buttonView.isPressed()) { //判断view是否是用户点击
                    return;
                }
                if (isChecked){
                    for (int i = 0; i < alldataBeans.size(); i++) {
                        alldataBeans.get(i).setChecked(true);
                    }
                    tv_add.setBackgroundResource(R.drawable.dfb9129_bg_r19);
                }else {
                    for (int i = 0; i < alldataBeans.size(); i++) {
                        alldataBeans.get(i).setChecked(false);
                    }
                    tv_add.setBackgroundResource(R.drawable.d999999_bg_r19);
                }

                shopInGoodslibrarListAdapter.refreshDatas(alldataBeans);
            }
        });

        rv_librarygoods.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (newState == RecyclerView.SCROLL_STATE_IDLE || newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                    // DES: 找出当前可视Item位置
                    RecyclerView.LayoutManager layoutManager = rv_librarygoods.getLayoutManager();
                    if (layoutManager instanceof LinearLayoutManager) {
                        LinearLayoutManager linearManager = (LinearLayoutManager) layoutManager;
                        //mFirstVisiblePosition = linearManager.findFirstVisibleItemPosition();
                        mLastVisiblePosition = linearManager.findLastVisibleItemPosition();
                        if (mLastVisiblePosition>8){
                            img_returntop.setVisibility(View.VISIBLE);
                        }else {
                            img_returntop.setVisibility(View.GONE);
                        }
                    }
                }
            }

            @Override
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                Log.e("","");
            }
        });
    }

    //切换分类调用
    private void changeCatoryType(int position, List<OneCategoryBeen.DataBean> catoryDate) {
        page = 1;
        Map<String,Object> map = new HashMap<>();
        map.put("storeId",storeId);
        map.put("page",page);
        map.put("goodsType","0");

        categoryId = catoryDate.get(position).getId()+"";
        map.put("categoryId",categoryId);

        if (isSearch == 1){//如果当前是搜索状态
            selPosition = position;
            if (EmptyUtil.isNotEmpty(searchMessage)){
                map.put("keyword",searchMessage);
            }

            mPresenter.getLibraryList(true,true,map);
            //清除搜索框
            //EventBus.getDefault().post(new SearchGoodsCloseMessage(0));
        }else {
            selPosition = position;
            mPresenter.getLibraryList(true,true,map);
        }
            catoryTitle =catoryDate.get(position).getName();
            catoryListAdapter.notifyDataSetChanged();
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_add://导入产品
                isShowToast = true;
                isSelGoods();
                break;
            case R.id.img_returntop://返回顶部
                rv_librarygoods.scrollToPosition(0);
                img_returntop.setVisibility(View.GONE);
                break;

        }
    }

    /**判断是否选择了商品*/
    private boolean isSelGoods() {
        selBeans.clear();
        for (int i = 0; i < alldataBeans.size(); i++) {
            if (alldataBeans.get(i).isChecked()){
                //selBeans.add(new GoodsLiblaryListSelBean(alldataBeans.get(i).getId()+"",alldataBeans.get(i).getTitle()));
                selBeans.add(new GoodsLiblaryListSelBean(alldataBeans.get(i).getId()+"",""));
            }
        }

        if (EmptyUtil.isNotEmpty(selBeans)){
            initSelCatoryDialog();
//                    Map<String,Object> map = new HashMap<>();
//                    map.put("data",new Gson().toJson(selBeans));
//                    map.put("storeId",storeId);
//                    mPresenter.addGoods(map);

//            if (oldSelCatoryPosition == position){
//                catoryTitle = catoryDate.get(position).getName();
//                Log.e("catoryTitle",catoryTitle+"---");
//            }else {
//                catoryTitle = catoryDate.get(oldSelCatoryPosition).getName();
//                oldSelCatoryPosition = position;
//                Log.e("catoryTitle",catoryTitle+"===");
//            }
            return true;

        }else {
            if (isShowToast)
            Toast.makeText(getActivity(), "请选择商品", Toast.LENGTH_SHORT).show();
            return false;
        }
    }

    @Override
    public void showLoading() {
        if (!ProgressDialog.getInstance().materialDialog.isShowing()) {
            ProgressDialog.getInstance().show(getActivity());
        }
    }


    @Override
    public void hideLoading() {
        ProgressDialog.getInstance().dismiss();
    }

    @Override
    public void onError(Throwable throwable) {

    }

    @Override
    public void onGoodListSuccess(ShopInGoodListBeen bean) {
    }


    @Override
    public void finishRefresh() {
        mRefreshLayout.finishRefresh(true);//刷新完成
    }

    @Override
    public void finishLoadMore() {
        mRefreshLayout.finishLoadMore(true);//加载完成
    }

    @Override
    public void onGoodsUpStateSuccess(GoodsUpStateBeen bean, int position) {

    }

    @Override
    public void onUpdateNumPriceSuccess(UpdateNumPriceBeen bean) {

    }

    @Override
    public void getLibraryListSuccess(GoodsLiblaryListBean bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {

            if (page == 1){
                if (checkbox_all.isChecked()){
                    checkbox_all.setChecked(false);
                }
                libraryData.clear();
                alldataBeans.clear();
                mRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
                    @Override
                    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {

                        Map<String,Object> map = new HashMap<>();
                        map.put("storeId",storeId);
                        map.put("page",page);
                        map.put("goodsType","0");
                        if (isSearch==1){//搜索商品
                            map.put("keyword",searchMessage);
                        }else {
                            map.put("keyword","");
                            if (EmptyUtil.isNotEmpty(categoryId)){
                                map.put("categoryId",categoryId);
                            }
                        }
                        mPresenter.getLibraryList(false,true,map);
                    }
                });
                if (EmptyUtil.isNotEmpty(bean.getData())){
                    libraryData = bean.getData();
                    alldataBeans = bean.getData();
                    shopInGoodslibrarListAdapter.refreshDatas(libraryData);
                    llHint.setVisibility(View.GONE);
                }else {
                    llHint.setVisibility(View.VISIBLE);
                    tvHint.setText("没有搜索到商品哦");
                }

                //alldataBeans.clear();
                selBeans.clear();
                tv_add.setBackgroundResource(R.drawable.d999999_bg_r19);

            }else {
                if (EmptyUtil.isNotEmpty(bean.getData())){
                    shopInGoodslibrarListAdapter.addDatas(bean.getData());
                    alldataBeans.addAll(bean.getData());

                    if (checkbox_all.isChecked()){
                        checkbox_all.setChecked(false);
                    }
                }
            }

            if (EmptyUtil.isEmpty(bean.getData())) {
                mRefreshLayout.finishLoadMoreWithNoMoreData();
            } else {
                page++;
            }

        } else {
            if (bean.getStatus() == Constants.LOGIN_CODE) {
                UtilsData.getPreference(getActivity(), "login").remove("head_url");
                UtilsData.getPreference(getActivity(), "login").remove("nickname");
                UtilsData.getPreference(getActivity(), "login").remove("is_store");
                UtilsData.getPreference(getActivity(), "login").remove("token");
                APP_TOKEN = "";
                Intent intent = new Intent(getActivity(), OneLoginMainActivity.class);
                startActivity(intent);
                return;
            }
            Toast.makeText(getActivity(), bean.getMsg(), Toast.LENGTH_SHORT).show();
        }

    }

    @Override
    public void getOneCategorySuccess(OneCategoryBeen bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            catoryDate = bean.getData();

            if (EmptyUtil.isNotEmpty(catoryDate)){
                catoryTitle = catoryDate.get(oldSelCatoryPosition).getName();
                categoryId =catoryDate.get(0).getId()+"";
                catoryDate.get(0).setCheck(true);
                catoryListAdapter.refreshDatas(catoryDate);
            }

        } else {
            if (bean.getStatus() == Constants.LOGIN_CODE) {
                UtilsData.getPreference(getActivity(), "login").remove("head_url");
                UtilsData.getPreference(getActivity(), "login").remove("nickname");
                UtilsData.getPreference(getActivity(), "login").remove("is_store");
                UtilsData.getPreference(getActivity(), "login").remove("token");
                APP_TOKEN = "";
                Intent intent = new Intent(getActivity(), OneLoginMainActivity.class);
                startActivity(intent);
                return;
            }
            Toast.makeText(getActivity(), bean.getMsg(), Toast.LENGTH_SHORT).show();
        }

    }

    @Override
    public void addGoodsSuccess(OneCategoryBeen bean,String catoryId) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            Toast.makeText(getActivity(), bean.getMsg(), Toast.LENGTH_SHORT).show();
//            page = 1;
//            Map<String,Object> map = new HashMap<>();
//            map.put("storeId",storeId);
//            map.put("page",page);
//            map.put("goodsType","0");
//            if (EmptyUtil.isNotEmpty(catoryId)){
//                map.put("categoryId",catoryId);
//            }
//            mPresenter.getLibraryList(true,true,map);
            changeCatoryType(clickCatoryPosition,catoryDate);
            Log.e("clickCatoryPosition",clickCatoryPosition+"-----");

            if (checkbox_all.isChecked()){
                checkbox_all.setChecked(false);
            }
        } else {
            if (bean.getStatus() == Constants.LOGIN_CODE) {
                UtilsData.getPreference(getActivity(), "login").remove("head_url");
                UtilsData.getPreference(getActivity(), "login").remove("nickname");
                UtilsData.getPreference(getActivity(), "login").remove("is_store");
                UtilsData.getPreference(getActivity(), "login").remove("token");
                APP_TOKEN = "";
                Intent intent = new Intent(getActivity(), OneLoginMainActivity.class);
                startActivity(intent);
                return;
            }
            Toast.makeText(getActivity(), bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void getCategoryListSuccess(ShopAddGoodTypeBeen bean) {
        if (bean.getStatus() == Constants.SUCCESS_CODE) {
            if (EmptyUtil.isNotEmpty(bean.getData())){
                catoryList = bean.getData();
                catoryList.get(0).setCheck(true);
            }
        }else {
            Toast.makeText(getActivity(), bean.getMsg(), Toast.LENGTH_SHORT).show();
        }
    }

    @Subscribe(threadMode = ThreadMode.POSTING)
    public void XXX(UpdateMessage messageEvent) {
        if (messageEvent.getMessage().equals(orderType)) {

            page = 1;
            Map<String,Object> map = new HashMap<>();
            map.put("storeId",storeId);
            map.put("page",page);
            map.put("goodsType","0");
            if (EmptyUtil.isNotEmpty(searchMessage)){
                map.put("keyword",searchMessage);
            }else {
                if (EmptyUtil.isNotEmpty(categoryId)){
                    map.put("categoryId",categoryId);
                }
            }

            mPresenter.getLibraryList(true,true,map);
        }

    }

    @Subscribe(threadMode = ThreadMode.POSTING)
    public void onSearchEvent(SearchGoodsContentMessage messageEvent) {
        if (messageEvent.getPage() == 4){//商品库页面搜索
            isSearch = messageEvent.getIsSearch();
            Log.e("isSearch",isSearch+"--onSearchEvent");
            if (messageEvent.getIsSearch()==0){//删除了搜索内容
                searchMessage = "";
                page = 1;
                Map<String,Object> map = new HashMap<>();
                map.put("storeId",storeId);
                map.put("page",page);
                map.put("goodsType","0");
                if (EmptyUtil.isNotEmpty(categoryId)){
                    map.put("categoryId",categoryId);
                }
Log.e("categoryId",categoryId+"-onSearchEvent--");
                mPresenter.getLibraryList(true,false,map);
                llHint.setVisibility(View.GONE);
            }else {//点击了搜索

                searchMessage = messageEvent.getSearchMessage();
                Log.e("searchMessage",searchMessage+"---");
                page = 1;
                Map<String,Object> map = new HashMap<>();
                map.put("storeId",storeId);
                map.put("page",page);
                map.put("goodsType","0");
                if (EmptyUtil.isNotEmpty(categoryId)){
                    map.put("categoryId",categoryId);
                }
                map.put("keyword",messageEvent.getSearchMessage());

                mPresenter.getLibraryList(true,false,map);
//                if (selPosition>=0){
//                    catoryDate.get(selPosition).setCheck(false);
//                }
//                categoryId = "";
//                catoryListAdapter.refreshDatas(catoryDate);
                KeybordUtil.hideKeyboard(getActivity());
//                selPosition = -1;
            }
        }else {
            if (messageEvent.getIsSearch()==0){
                searchMessage = "";
            }else {
                searchMessage = messageEvent.getSearchMessage();
                categoryId = "";
            }
        }
    }



    public static ShopInGoodLibraryFragment newInstance(String orderType, String styleType) {
        Bundle bundle = new Bundle();
        bundle.putString("orderType", orderType + "");
        bundle.putString("styleType", styleType + "");
        ShopInGoodLibraryFragment fragment = new ShopInGoodLibraryFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onDestroyView() {
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
        if (dialog.isShowing()) {
            dialog.dismiss();
        }
        super.onDestroyView();
    }

    @Override
    public void onDestroy() {
        mList.clear();
        mList = null;
        super.onDestroy();
    }
}
